<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h2{
            width: 1200px;
            margin: 50px auto 20px;
            padding-bottom:10px ;
            font-size: 30px;
            border-bottom:1px solid gray ;
        }
        button{
            border-radius: 5px;
            height: 35px;
            width: 100px;   
            background-color: blueviolet;
            float: left;
            margin-right: 10px;
            color: white;
            border: none;
            text-align: center;
        }
        .btn-primary{
            margin-left: 160px;
            background-color: #cd6969;
        }
        .btn-danger{
            background-color: orange;
        }
    </style>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
</head>
<body>
    <h2>jQuery发送Ajax请求</h2>
    <button class="btn btn-primary">GET</button>
    <button class="btn btn-danger">POST</button>
    <button class="btn btn-info">通用型方法</button>
    <script>
        const btns = document.querySelectorAll('button')
        btns[0].onclick = function(){
            //GET请求
            axios.get('http://localhost:8000/axios-server', {
                //url参数
                params:{
                    id:1000,
                    vip:12
                },
                //请求头信息
                headers:{
                    name:'hanser',
                    age:'2'
                }
            }).then(value=>{
                console.log(value)
            })
        }
        btns[1].onclick = function(){

            axios.post('http://localhost:8000/axios-server', {
                    username:'admin',
                    password:'123'
                },{
                //url参数
                params:{
                    id:1,
                    vip:123
                },
                //请求头参数
                headers:{
                    name:'yousa',
                    age:'23'
                },
                //请求体
               
            })
        }

        btns[2].onclick = function(){
            axios({
                method:'POST',
                url:'http://localhost:8000/axios-server',
                //url参数
                params:{
                    vip:10,
                    id:123
                },
                //头信息
                headers:{
                    a:100,
                    b:200
                },
                //请求体参数
                data:{
                    name:'hanser',
                    age:'7'
                }
            }).then(response=>{
                console.log(response)
            })
        }
    </script>
</body>
</html>